
import bpy


from 全局控制.Node.节点和插座基类.bl_UpdateNode import *
from 对象操作 import bl_对象变换帧

import 全局控制.Node.节点和插座基类.bl_节点基类 as 基类
from 全局控制.Node.节点数据类型 import bl_集合数据类型

from bpy.types import Operator, Menu
from bl_operators.presets import AddPresetBase





E_类型枚举 = [
	("TYPE_父级", "parect", "", 0),
	
]




class C_SN_物体关系(基类.C_SN_基类):
	bl_dname = 'bl_node_物体关系'
	bl_label = '物体关系'
	
	m_关系类型 = bpy.props.EnumProperty(items = E_类型枚举, name="函数", default="TYPE_父级" )
	#m_修改器类型 = bpy.props.StringProperty(name="修改器类型")
	#m_投影物体 = bpy.props.CollectionProperty(type=bl_集合数据类型.C_物体组元素)
	#m_projector_count = bpy.props.IntProperty(update=f_投影物体数量update)
	def init(self, context):
		super(C_SN_物体关系, self).f_init(context)
		
		self.inputs.new('C_NodeSocket_物体', name='父对象')
		self.inputs.new('C_插座_物体2D', name='子物体')
		#self.inputs.new('C_NodeSocket_bool', name='是否隐藏')

	def draw_buttons(self, context, layout):
		pass
				
	def f_update(self, 是否向下传递=False, input插座=None):
		parents = self.inputs['父对象'].f_getData()
		子 = self.inputs['子物体'].f_getData()
		#print('子= ', 子)
		index = 0
		for obj in parents:
			for 子物体 in 子[index] :
				子物体.parent = obj
			index += 1


		super(C_SN_物体关系, self).f_update(是否向下传递, input插座)


class C_NODE_MENU_物体关系(bpy.types.Operator):
	bl_idname = 'node.global_node_obj_relations'
	bl_label = '物体关系'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_SN_物体关系', use_transform=True)
		return {'FINISHED'}





classes = (
	C_SN_物体关系,
	C_NODE_MENU_物体关系,

)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		
def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)


